﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using Delonix_Regia_Hotel_Management_System.Class;

namespace Delonix_Regia_Hotel_Management_System
{
    public partial class Room_Occupancy_Report : Form
    {
        public Room_Occupancy_Report()
        {
            InitializeComponent();
        }

        private void button1_Click(object sender, EventArgs e)
        {
            if (LogInClass.position == "Administrator")
            {
                Main__Management_and_Administrator_ mainA = new Main__Management_and_Administrator_();
                this.Hide();
                mainA.Show();
            }
            else
            {
                Main__Receptionist_ mainR = new Main__Receptionist_();
                this.Hide();
                mainR.Show();
            }

        }

        private void button2_Click(object sender, EventArgs e)
        {
            Form1 F = new Form1();
            this.Hide();
            F.Show(); 
        }

        private void btnGenerateDailyReport_Click(object sender, EventArgs e)
        {
            if (comboBox1.SelectedItem.Equals("Daily"))
            {
                List<RoomBooking> RoomList = DBManager.getAllRoomForDaily();

                dataGridView1.DataSource = RoomList;
                dataGridView1.RowHeadersVisible = false;
                dataGridView1.Columns[0].Visible = false;
                dataGridView1.Columns[1].Visible = false;
                dataGridView1.Columns[2].Visible = false;
                dataGridView1.Columns[3].Visible = false;
                dataGridView1.Columns[7].Visible = false;
                dataGridView1.Columns[8].Visible = false;

                dataGridView1.Columns[9].HeaderText = "roomNum";
                dataGridView1.Columns[9].DisplayIndex = 0;

                if (RoomList.Count == 0)
                {
                    MessageBox.Show("No record found!");
                }
            }

            else if (comboBox1.SelectedItem.Equals("Weekly"))
            {
                int week = Convert.ToInt32(tbxWeek.Text);
                List<RoomBooking> r = DBManager.getRoomOccupancyWeek(week);

                dataGridView1.DataSource = r;
                dataGridView1.RowHeadersVisible = false;
                dataGridView1.Columns[0].Visible = false;
                dataGridView1.Columns[1].Visible = false;
                dataGridView1.Columns[2].Visible = false;
                dataGridView1.Columns[3].Visible = false;
                dataGridView1.Columns[7].Visible = false;
                dataGridView1.Columns[8].Visible = false;

                dataGridView1.Columns[9].HeaderText = "roomNum";
                dataGridView1.Columns[9].DisplayIndex = 0;

                tbxWeek.Clear();

                if (r.Count == 0)
                {
                    MessageBox.Show("No record found!");
                }
            }

            else if (comboBox1.SelectedItem.Equals("Monthly"))
            {
                if (comboBox2.SelectedItem.Equals("January"))
                {
                    int month = 1;
                    List<RoomBooking> r1 = DBManager.getRoomOccupancyMonth(month);

                    dataGridView1.DataSource = r1;
                    dataGridView1.RowHeadersVisible = false;
                    dataGridView1.Columns[0].Visible = false;
                    dataGridView1.Columns[1].Visible = false;
                    dataGridView1.Columns[2].Visible = false;
                    dataGridView1.Columns[3].Visible = false;
                    dataGridView1.Columns[7].Visible = false;
                    dataGridView1.Columns[8].Visible = false;

                    dataGridView1.Columns[9].HeaderText = "roomNum";
                    dataGridView1.Columns[9].DisplayIndex = 0;

                    if (r1.Count == 0)
                    {
                        MessageBox.Show("No record found!");
                    }
                }
                else if (comboBox2.SelectedItem.Equals("February"))
                {
                    int month = 2;
                    List<RoomBooking> r1 = DBManager.getRoomOccupancyMonth(month);

                    dataGridView1.DataSource = r1;
                    dataGridView1.RowHeadersVisible = false;
                    dataGridView1.Columns[0].Visible = false;
                    dataGridView1.Columns[1].Visible = false;
                    dataGridView1.Columns[2].Visible = false;
                    dataGridView1.Columns[3].Visible = false;
                    dataGridView1.Columns[7].Visible = false;
                    dataGridView1.Columns[8].Visible = false;

                    dataGridView1.Columns[9].HeaderText = "roomNum";
                    dataGridView1.Columns[9].DisplayIndex = 0;

                    if (r1.Count == 0)
                    {
                        MessageBox.Show("No record found!");
                    }
                }
                else if (comboBox2.SelectedItem.Equals("March"))
                {
                    int month = 3;
                    List<RoomBooking> r1 = DBManager.getRoomOccupancyMonth(month);

                    dataGridView1.DataSource = r1;
                    dataGridView1.RowHeadersVisible = false;
                    dataGridView1.Columns[0].Visible = false;
                    dataGridView1.Columns[1].Visible = false;
                    dataGridView1.Columns[2].Visible = false;
                    dataGridView1.Columns[3].Visible = false;
                    dataGridView1.Columns[7].Visible = false;
                    dataGridView1.Columns[8].Visible = false;

                    dataGridView1.Columns[9].HeaderText = "roomNum";
                    dataGridView1.Columns[9].DisplayIndex = 0;

                    if (r1.Count == 0)
                    {
                        MessageBox.Show("No record found!");
                    }
                }
                else if (comboBox2.SelectedItem.Equals("April"))
                {
                    int month = 4;
                    List<RoomBooking> r1 = DBManager.getRoomOccupancyMonth(month);

                    dataGridView1.DataSource = r1;
                    dataGridView1.RowHeadersVisible = false;
                    dataGridView1.Columns[0].Visible = false;
                    dataGridView1.Columns[1].Visible = false;
                    dataGridView1.Columns[2].Visible = false;
                    dataGridView1.Columns[3].Visible = false;
                    dataGridView1.Columns[7].Visible = false;
                    dataGridView1.Columns[8].Visible = false;

                    dataGridView1.Columns[9].HeaderText = "roomNum";
                    dataGridView1.Columns[9].DisplayIndex = 0;

                    if (r1.Count == 0)
                    {
                        MessageBox.Show("No record found!");
                    }
                }
                else if (comboBox2.SelectedItem.Equals("May"))
                {
                    int month = 5;
                    List<RoomBooking> r1 = DBManager.getRoomOccupancyMonth(month);

                    dataGridView1.DataSource = r1;
                    dataGridView1.RowHeadersVisible = false;
                    dataGridView1.Columns[0].Visible = false;
                    dataGridView1.Columns[1].Visible = false;
                    dataGridView1.Columns[2].Visible = false;
                    dataGridView1.Columns[3].Visible = false;
                    dataGridView1.Columns[7].Visible = false;
                    dataGridView1.Columns[8].Visible = false;

                    dataGridView1.Columns[9].HeaderText = "roomNum";
                    dataGridView1.Columns[9].DisplayIndex = 0;

                    if (r1.Count == 0)
                    {
                        MessageBox.Show("No record found!");
                    }
                }
                else if (comboBox2.SelectedItem.Equals("June"))
                {
                    int month = 6;
                    List<RoomBooking> r1 = DBManager.getRoomOccupancyMonth(month);

                    dataGridView1.DataSource = r1;
                    dataGridView1.RowHeadersVisible = false;
                    dataGridView1.Columns[0].Visible = false;
                    dataGridView1.Columns[1].Visible = false;
                    dataGridView1.Columns[2].Visible = false;
                    dataGridView1.Columns[3].Visible = false;
                    dataGridView1.Columns[7].Visible = false;
                    dataGridView1.Columns[8].Visible = false;

                    dataGridView1.Columns[9].HeaderText = "roomNum";
                    dataGridView1.Columns[9].DisplayIndex = 0;

                    if (r1.Count == 0)
                    {
                        MessageBox.Show("No record found!");
                    }
                }
                else if (comboBox2.SelectedItem.Equals("July"))
                {
                    int month = 7;
                    List<RoomBooking> r1 = DBManager.getRoomOccupancyMonth(month);

                    dataGridView1.DataSource = r1;
                    dataGridView1.RowHeadersVisible = false;
                    dataGridView1.Columns[0].Visible = false;
                    dataGridView1.Columns[1].Visible = false;
                    dataGridView1.Columns[2].Visible = false;
                    dataGridView1.Columns[3].Visible = false;
                    dataGridView1.Columns[7].Visible = false;
                    dataGridView1.Columns[8].Visible = false;

                    dataGridView1.Columns[9].HeaderText = "roomNum";
                    dataGridView1.Columns[9].DisplayIndex = 0;

                    if (r1.Count == 0)
                    {
                        MessageBox.Show("No record found!");
                    }
                }
                else if (comboBox2.SelectedItem.Equals("August"))
                {
                    int month = 8;
                    List<RoomBooking> r1 = DBManager.getRoomOccupancyMonth(month);

                    dataGridView1.DataSource = r1;
                    dataGridView1.RowHeadersVisible = false;
                    dataGridView1.Columns[0].Visible = false;
                    dataGridView1.Columns[1].Visible = false;
                    dataGridView1.Columns[2].Visible = false;
                    dataGridView1.Columns[3].Visible = false;
                    dataGridView1.Columns[7].Visible = false;
                    dataGridView1.Columns[8].Visible = false;

                    dataGridView1.Columns[9].HeaderText = "roomNum";
                    dataGridView1.Columns[9].DisplayIndex = 0;

                    if (r1.Count == 0)
                    {
                        MessageBox.Show("No record found!");
                    }
                }
                else if (comboBox2.SelectedItem.Equals("September"))
                {
                    int month = 9;
                    List<RoomBooking> r1 = DBManager.getRoomOccupancyMonth(month);

                    dataGridView1.DataSource = r1;
                    dataGridView1.RowHeadersVisible = false;
                    dataGridView1.Columns[0].Visible = false;
                    dataGridView1.Columns[1].Visible = false;
                    dataGridView1.Columns[2].Visible = false;
                    dataGridView1.Columns[3].Visible = false;
                    dataGridView1.Columns[7].Visible = false;
                    dataGridView1.Columns[8].Visible = false;

                    dataGridView1.Columns[9].HeaderText = "roomNum";
                    dataGridView1.Columns[9].DisplayIndex = 0;

                    if (r1.Count == 0)
                    {
                        MessageBox.Show("No record found!");
                    }
                }
                else if (comboBox2.SelectedItem.Equals("October"))
                {
                    int month = 10;
                    List<RoomBooking> r1 = DBManager.getRoomOccupancyMonth(month);

                    dataGridView1.DataSource = r1;
                    dataGridView1.RowHeadersVisible = false;
                    dataGridView1.Columns[0].Visible = false;
                    dataGridView1.Columns[1].Visible = false;
                    dataGridView1.Columns[2].Visible = false;
                    dataGridView1.Columns[3].Visible = false;
                    dataGridView1.Columns[7].Visible = false;
                    dataGridView1.Columns[8].Visible = false;

                    dataGridView1.Columns[9].HeaderText = "roomNum";
                    dataGridView1.Columns[9].DisplayIndex = 0;

                    if (r1.Count == 0)
                    {
                        MessageBox.Show("No record found!");
                    }
                }
                else if (comboBox2.SelectedItem.Equals("November"))
                {
                    int month = 11;
                    List<RoomBooking> r1 = DBManager.getRoomOccupancyMonth(month);

                    dataGridView1.DataSource = r1;
                    dataGridView1.RowHeadersVisible = false;
                    dataGridView1.Columns[0].Visible = false;
                    dataGridView1.Columns[1].Visible = false;
                    dataGridView1.Columns[2].Visible = false;
                    dataGridView1.Columns[3].Visible = false;
                    dataGridView1.Columns[7].Visible = false;
                    dataGridView1.Columns[8].Visible = false;

                    dataGridView1.Columns[9].HeaderText = "roomNum";
                    dataGridView1.Columns[9].DisplayIndex = 0;

                    if (r1.Count == 0)
                    {
                        MessageBox.Show("No record found!");
                    }
                }
                else if (comboBox2.SelectedItem.Equals("December"))
                {
                    int month = 12;
                    List<RoomBooking> r1 = DBManager.getRoomOccupancyMonth(month);

                    dataGridView1.DataSource = r1;
                    dataGridView1.RowHeadersVisible = false;
                    dataGridView1.Columns[0].Visible = false;
                    dataGridView1.Columns[1].Visible = false;
                    dataGridView1.Columns[2].Visible = false;
                    dataGridView1.Columns[3].Visible = false;
                    dataGridView1.Columns[7].Visible = false;
                    dataGridView1.Columns[8].Visible = false;

                    dataGridView1.Columns[9].HeaderText = "roomNum";
                    dataGridView1.Columns[9].DisplayIndex = 0;
                    
                    
                    if (r1.Count == 0)
                    {
                        MessageBox.Show("No record found!");
                    }
                }
            }

            else if (comboBox1.SelectedItem.Equals("Yearly"))
            {
                int year = Convert.ToInt32(tbxYear.Text);
                List<RoomBooking> r = DBManager.getRoomOccupancyYear(year);

                dataGridView1.DataSource = r;
                dataGridView1.RowHeadersVisible = false;
                dataGridView1.Columns[0].Visible = false;
                dataGridView1.Columns[1].Visible = false;
                dataGridView1.Columns[2].Visible = false;
                dataGridView1.Columns[3].Visible = false;
                dataGridView1.Columns[7].Visible = false;
                dataGridView1.Columns[8].Visible = false;

                dataGridView1.Columns[9].HeaderText = "roomNum";
                dataGridView1.Columns[9].DisplayIndex = 0;

                tbxYear.Clear();
                    
                if (r.Count == 0)
                {
                    MessageBox.Show("No record found!");
                }
            }
        }

        private void comboBox1_SelectedIndexChanged(object sender, EventArgs e)
        {
            if (comboBox1.SelectedItem.Equals("Daily"))
            {
                lblEnterWeek.Visible = false;
                tbxWeek.Visible = false;

                lblMonth.Visible = false;
                comboBox2.Visible = false;
                lblYear.Visible = false;
                tbxYear.Visible = false;
            }
            else if (comboBox1.SelectedItem.Equals("Weekly"))
            {
                lblEnterWeek.Visible = true;
                tbxWeek.Visible = true;

                lblMonth.Visible = false;
                comboBox2.Visible = false;
                lblYear.Visible = false;
                tbxYear.Visible = false;
            }
            else if (comboBox1.SelectedItem.Equals("Monthly"))
            {
                lblMonth.Visible = true;
                comboBox2.Visible = true;

                lblEnterWeek.Visible = false;
                tbxWeek.Visible = false;
                lblYear.Visible = false;
                tbxYear.Visible = false;
            }

            else if (comboBox1.SelectedItem.Equals("Yearly"))
            {
                lblYear.Visible = true;
                tbxYear.Visible = true;
                
                lblMonth.Visible = false;
                comboBox2.Visible = false;

                lblEnterWeek.Visible = false;
                tbxWeek.Visible = false;
            }
        }

        private void btnExportToExcel_Click(object sender, EventArgs e)
        {
            Microsoft.Office.Interop.Excel.ApplicationClass ExcelApp = new Microsoft.Office.Interop.Excel.ApplicationClass();
            ExcelApp.Application.Workbooks.Add(Type.Missing);
            ExcelApp.Columns.ColumnWidth = 10;

            ExcelApp.Cells[1, 1] = dataGridView1.Columns[9].HeaderText;
            ExcelApp.Cells[1, 2] = dataGridView1.Columns[4].HeaderText;
            ExcelApp.Cells[1, 3] = dataGridView1.Columns[5].HeaderText;
            ExcelApp.Cells[1, 4] = dataGridView1.Columns[6].HeaderText;

            for (int i = 0; i < dataGridView1.Rows.Count; i++)
            {
                ExcelApp.Cells[i + 2, 1] = dataGridView1.Rows[i].Cells[9].Value.ToString();
                ExcelApp.Cells[i + 2, 2] = dataGridView1.Rows[i].Cells[4].Value.ToString();
                ExcelApp.Cells[i + 2, 3] = dataGridView1.Rows[i].Cells[5].Value.ToString();
                ExcelApp.Cells[i + 2, 4] = dataGridView1.Rows[i].Cells[6].Value.ToString();
            }

            string datetime = DateTime.Now.ToString("MMddyyyyhmmtt");
            ExcelApp.ActiveWorkbook.SaveCopyAs("F:\\RoomOccupancyReport" + datetime + ".xls");
            ExcelApp.ActiveWorkbook.Saved = true;
            ExcelApp.Quit();
            MessageBox.Show("Excel file created,you can find the file F:\\RoomOccupancyReport.xls");
        }

        private void btnPreview_Click(object sender, EventArgs e)
        {
            PrintDGV.Print_DataGridView(dataGridView1);
        }
    }
}
